/*
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?

Anser:104743
Time:435.298663ms
*/
package main

import (
	"fmt"
	"time"
)

func main() {
	tstart := time.Now()
	n := 0
	for i := 2; ; i++ {
		if prime(i) {
			n++
			if n == 10001 {
				fmt.Println(i)
				break
			}
		}
	}
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}

// s 存放质数
var s = make([]int, 0)

// prime 判断是否是质数，并将质数写入s
func prime(n int) bool {
	if n < 2 {
		return false
	}
	if n > 2 {
		for _, v := range s {
			if n%v == 0 {
				return false
			}
		}
	}
	s = append(s, n)
	return true
}
